package io.wongd.lib_douyin.db

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import java.io.Serializable


@Entity(tableName = "douyin")
data class DouyinBean(
    @PrimaryKey(autoGenerate = true)
    var id: Int = 0,
    @ColumnInfo(name = "author_id")
    var authorID: String = "",
    @ColumnInfo(name = "author_nick")
    var authorNick: String = "",
    @ColumnInfo(name = "aweme_id", index = true)
    var awemeID: String = "",
    // 0: 视频，68: 图片
    @ColumnInfo(name = "aweme_type")
    var awemeType: Int = 0,
    @ColumnInfo("title")
    var title: String = "",
    @ColumnInfo("max_cursor")
    var maxCursor: Long = 0L,
    @ColumnInfo("next_max_cursor")
    var nextMaxCursor: Long = 0L,
    @ColumnInfo("has_more")
    var hasMore: Int = 0,
    // 封面的图片地址
    @ColumnInfo(name = "cover_url")
    var coverUrl: String = "",
    // 无水印图片地址
    @ColumnInfo(name = "image_list")
    var imageList: List<String> = emptyList(),
    // 无水印视频地址
    @ColumnInfo(name = "play_api")
    var playApi: String = "",
    @ColumnInfo(name = "local_file_map")
    var localFileMap: Map<String, String> = mapOf(),
    val viewType: Int = douyinViewTypeItem,
) : Serializable {

    val isItem
        get() = viewType and douyinViewTypeItem != 0

    val isHeader
        get() = viewType and douyinViewTypeHeader != 0

    val isFooter
        get() = viewType and douyinViewTypeFooter != 0

    val isVideo
        get() = awemeType == 0

}

private const val douyinViewTypeItem = 1
private const val douyinViewTypeHeader = 1 shl 1
private const val douyinViewTypeFooter = 1 shl 2

val douyinHeader = DouyinBean(awemeID = "douyinViewTypeHeader", viewType = douyinViewTypeHeader)
val douyinFooter = DouyinBean(awemeID = "douyinViewTypeFooter", viewType = douyinViewTypeFooter)